#include<iostream>
#include<vector>
#include<set>
using namespace std;
using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (auto &x : a) cin >> x;
    set<ll> s;
    ll sum = 0;
    for (int i = n - 1; i >= 0; --i) {
        auto it = s.lower_bound(a[i]);
        if (it != s.begin()) {
            --it;
			ll tmp=a[i]+*it; 
            sum = max(sum, tmp);
        }
        s.insert(a[i]);
    }
    cout << sum << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}
